package com.linghu.influx;

import com.influxdb.client.WriteApiBlocking;
import com.linghu.influx.entity.DemoPOJO;

/**
 * @author 令狐荣豪
 * @version 1.0
 */


import java.time.Instant;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.domain.WritePrecision;

public class InfluxDB2POJOInsertExample {
    public static void main(final String[] args) {
        // You can generate an API token from the "API Tokens Tab" in the UI
        char[] token= "QTEG3Rpx6ErCFDypxdqMvhXXuh-Ot2cxkFvcLE1mr6Q_4DsE0AhYxq9u10y0EG2UGRcL_n7JAi902ITMnF1hRA==".toCharArray();
        String bucket = "linghu";
        String org = "haomeng";

        InfluxDBClient client = InfluxDBClientFactory.create("http://192.168.28.128:8086", token,org,bucket);
        WriteApiBlocking writeApiBlocking = client.getWriteApiBlocking();
        /** 用注解对象插入数据 */
        DemoPOJO pojo = new DemoPOJO("beijing", 26.2, Instant.now());
        try {
            writeApiBlocking.writeMeasurement(WritePrecision.MS,pojo);
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
        client.close();
    }
}

